<?php
require_once ('../lib/config.php');
require_once ('../lib/facebook.php');
require_once ('../lib/friends.php');
require_once ('../lib/friend.php');
require_once ('../lib/test.php');
require_once ('../../simpletest/autorun.php');
require_once ('../lib/init.php');
require_once ('../data_sample/mockup_data_post.php');

class TestFunc_processMyPost extends UnitTestCase {
    
    function setUp(){
        global $login_button,$facebook;
        
        //if there is a session, skip code for processting sesseion
        if(isLoggedIn()){
            try{
                $me = getOneself();
            }catch(Exception $e){
                print($login_button);
                exit();
            }
        }
    }

    /************************
     * Post Mockup Data  *
     ************************/
    
    //Case1: I wrote a post on one of friends' wall
    function test_case1(){ 
        global $postCase1;
        $data = $postCase1; 
        $friends = array();
        
        processMyPost($friends, $data);
        
        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        $this->assertFalse(empty($friends));

        //there must be one friend
        $this->assertTrue(count($friends) == 1);
        
        //And the friend must have One post
        $friend = $friends['100000416787478'];
        $this->assertEqual($friend->getNumberOfData("MY_POST_FLAG"),1);
    }

    //Case2: I wrote two posts on one of friends' wall
    function test_case2(){ 
        global $postCase2;
        $data = $postCase2; 
        $friends = array();
        
        processMyPost($friends, $data);
        
        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        $this->assertFalse(empty($friends));

        //there must be one friend
        $this->assertTrue(count($friends) == 1);
        
        //And the friend must have One post
        $friend = $friends['100000416787478'];
        $this->assertEqual($friend->getNumberOfData("MY_POST_FLAG"),2);
    }

    //Case3: I wrote a post on each of two friends' walls
    function test_case3(){ 
        global $postCase3;
        $data = $postCase3; 
        $friends = array();
        
        processMyPost($friends, $data);
        
        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        $this->assertFalse(empty($friends));

        //there must be two friend
        $this->assertEqual(count($friends),2);
        
        //And each friend must have One post
        $friend = $friends['100000416787478'];
        $this->assertEqual($friend->getNumberOfData("MY_POST_FLAG"),1);
        $friend = $friends['100000525262538'];
        $this->assertEqual($friend->getNumberOfData("MY_POST_FLAG"),1);
    }
    //Case4: I wrote posts on friends' walls (complicated scenario)
    //    3 posts on yool's, 2 posts on soon's    
    function test_case4(){ 
        global $postCase4;
        $data = $postCase4; 
        $friends = array();
        
        processMyPost($friends, $data);
        
        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        $this->assertFalse(empty($friends));

        //there must be two friend
        $this->assertEqual(count($friends),2);
        
        //And each friend must have One post
        $friend = $friends['100000416787478'];
        $this->assertEqual($friend->getNumberOfData("MY_POST_FLAG"),3);
        $friend = $friends['100000525262538'];
        $this->assertEqual($friend->getNumberOfData("MY_POST_FLAG"),2);
    }

    function test_real_data(){ 
        $friends = array();
        $data = getMyPost();

        processMyPost($friends, $data);
print_r($friends);
        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        //$this->assertFalse(empty($friends));

    }
}
?>
